<template>
  <div class="mod-sp__spnotice">
    <el-form :inline="true" :model="dataForm" @keyup.enter="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.title" placeholder="标题" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <!--matchList赛事下拉列表-->
        <el-input v-model="dataForm.matchName" placeholder="赛事" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="exportHandle()">{{ $t("export") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="hasPermission('sp:spnotice:save')" type="primary" @click="addOrUpdateHandle()">{{ $t("add") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="id" label="ID" header-align="center" align="center" width="80"></el-table-column>
      <el-table-column prop="title" label="标题" header-align="center" align="center" width="250"></el-table-column>
      <el-table-column prop="content" label="内容" header-align="center" align="center" width="450">
        <template v-slot="scope">
          <div v-if="scope.row.content.length > 30">{{ scope.row.content.substring(0, 30) }}...</div>
          <div v-else>
            {{ scope.row.content }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="createDate" label="创建时间" header-align="center" align="center"></el-table-column>
      <el-table-column prop="matchName" label="赛事/赛项" header-align="center" align="center"></el-table-column>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button v-if="hasPermission('sp:spnotice:update') && ((userInfo.sysUserType === '3' && scope.row.adminId == userInfo.id) || userInfo.superAdmin == 1)" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>
          <el-button v-if="hasPermission('sp:spnotice:delete') && ((userInfo.sysUserType === '3' && scope.row.adminId == userInfo.id) || userInfo.superAdmin == 1)" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList" :type="dataForm.type"></add-or-update>
  </div>
</template>

<script lang="ts">
import useView from "@/hooks/useView";
import { defineComponent, reactive, toRefs } from "vue";
import AddOrUpdate from "./spnotice-add-or-update.vue";
import baseService from "@/service/baseService";
import store from "@/store";
export default defineComponent({
  components: {
    AddOrUpdate
  },
  setup() {
    const state = reactive({
      getDataListURL: "/sp/spnotice/page",
      getDataListIsPage: true,
      exportURL: "/sp/spnotice/export",
      deleteURL: "/sp/spnotice",
      deleteIsBatch: true,
      dataForm: {
        businessId: "",
        title: "",
        type: "",
        matchName: ""
      },
      matchList: [],
      userInfo: store.state.user
    });
    return { ...useView(state), ...toRefs(state) };
  },
  watch: {},
  mounted() {
    console.log("----");
    console.log(store.state.user);
    //获取上个页面传来的参数
    this.dataForm.businessId = this.$route.query.id ? this.$route.query.id + "" : "";
    this.dataForm.type = this.$route.query.type ? this.$route.query.type + "" : "";
    this.getMatch();
  },
  methods: {
    // 查询赛事
    getMatch() {
      baseService.get("/sp/spmatch/list").then((res) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg);
        }
        this.matchList = res.data;
      });
    }
  }
});
</script>
